package com.lcy.springtest.conf;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author lichenyang
 * @create 2021-04-16 3:04 下午
 */
public class MacConditional implements Condition {

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        //context 可以获取当前环境信息
        Environment environment = context.getEnvironment();
        String property = environment.getProperty("os.name");
        // context 获取bean 定义的注册类, 可以判断容器中 bean的注册情况, 也可以给容器中注册bean
        BeanDefinitionRegistry registry = context.getRegistry();
        // 判断容器中是否存在已经注册好的 person 对象
        boolean person = registry.containsBeanDefinition("person");


        if(property.contains("Mac")){
            return true;
        }
        return false;
    }
}
